<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8"/>
  <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover, user-scalable=0">
  <meta name="Robots" content="noindex,nofollow,noarchive">
  <link rel="icon" type="image/png" href="../static/img/logo.png">
  <link rel="icon" type="image/png" sizes="32x32" href="../static/img/logo-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="../static/img/logo-16x16.png">
  <link rel="apple-touch-icon" sizes="256x256" href="../static/img/logo-black.png">
  <link rel="shortcut icon" href="../static/favicon.ico" type="image/x-icon">
  <link rel="apple-touch-startup-image" href="../static/img/startup.jpg">
  <link rel="manifest" href="../static/site.webmanifest" crossorigin="use-credentials">
  <meta name="mobile-web-app-capable" content="yes"/>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="apple-mobile-web-app-title" content="NAStool">
  <meta name="description" content="NAS媒体库资源归集整理自动化工具">
  <meta name="format-detection" content="telephone=no">
  <meta name="referrer" content="never">
  <meta name="apple-mobile-web-app-capable" content="yes"/>
  <meta name="msapplication-TileColor" content="#1e293b"/>
  <meta name="theme-color" content="#1e293b"/>
  <meta name="HandheldFriendly" content="True"/>
  <meta name="MobileOptimized" content="320"/>
  <title>NAStool - 资源归集、整理自动化工具</title>
  <!-- CSS files -->
  <link href="../static/css/font-awesome.min.css" rel="stylesheet">
  <link href="../static/css/tabler.min.css" rel="stylesheet"/>
  <link href="../static/css/demo.min.css" rel="stylesheet"/>
  <link href="../static/css/fullcalendar.min.css" rel="stylesheet"/>
  <link href="../static/css/jquery.filetree.css" rel="stylesheet"/>
  <link href="../static/css/dropzone.css" rel="stylesheet"/>
  <!-- 字体 -->
  <style>
      @import url('https://rsms.me/inter/inter.css');

      :root {
          --tblr-font-sans-serif: Inter, -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
      }
  </style>
  <!-- 附加样式 -->
  <style>
      body,
      .page {
          height: 100%;
          overflow: hidden;
      }

      .tooltip-inner {
          text-align: left;
      }

      .fileTree {
          width: 240px;
          max-height: 200px;
          overflow-y: scroll;
          overflow-x: hidden;
          position: absolute;
          display: none;
      }

      .navbar-vertical {
          padding-top: env(safe-area-inset-top) !important;
          position: fixed !important;
          left: 0 !important;
          right: 0 !important;
          top: 0 !important;
      }

      .navbar-expand-md {
          position: fixed !important;
          left: 0 !important;
          right: 0 !important;
          top: 0 !important;
      }

      @media (max-width: 992px) {
          .navbar ul.navbar-nav {
              overflow-y: auto;
              max-height: 80vh;
          }
      }

      .page-wrapper {
          margin-top: calc(env(safe-area-inset-top) + 50px) !important;
          height: 100% !important;
          overflow: scroll !important;
      }

      .offcanvas {
          padding-top: env(safe-area-inset-top) !important;
      }

      .modal-dialog {
          padding-top: env(safe-area-inset-top) !important;
      }
  </style>
  <!-- 站点图标 -->
  <style>
  {% for site_name, site_icon in SiteFavicons.items() %}
      .siteicon-{{ site_name|hash }} {
          background-image: url({{ site_icon }});
          background-size: cover;
          border: 0;
      }
  {% endfor %}
  </style>
</head>

<body>
<div class="page">
  <script src="../static/js/demo-theme.min.js"></script>
  <aside class="navbar navbar-vertical navbar-expand-lg navbar-dark sticky-top">
    <div class="container-xl">
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-auto-collapse="true"
              data-bs-target="#navbar-menu">
        <span class="navbar-toggler-icon"></span>
      </button>
      <h1 class="navbar-brand" style="filter:brightness(0) invert(1)">
        <a href="javascript:ScrollToTop()">
          <img src="../static/img/logo-blue.png" height="48" alt="NAStool" class="navbar-brand-image">
        </a>
      </h1>
      <div class="navbar-nav flex-row d-lg-none">
        <div class="nav-item dropdown">
          <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown">
              <span>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user" width="24" height="24"
                     viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                     stroke-linejoin="round">
                  <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                  <circle cx="12" cy="7" r="4"></circle>
                  <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"></path>
                </svg>
              </span>
            <div class="d-none d-xl-block ps-2">
              <div>{{ UserName }}</div>
            </div>
          </a>
          <div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
            <a class="dropdown-item hide-theme-dark" href="?theme=dark" role="button">暗黑风格</a>
            <a class="dropdown-item hide-theme-light" href="?theme=light" role="button">明亮风格</a>
            <div class="dropdown-divider"></div>
            {% if "系统设置" in UserPris %}
              <a class="dropdown-item" data-bs-toggle="offcanvas" href="#offcanvasEnd" role="button"
                 aria-controls="offcanvasEnd">消息中心</a>
              <a class="dropdown-item" href="javascript:show_logging_modal()" role="button">实时日志</a>
              <div class="dropdown-divider"></div>
              {% if SystemFlag > 0 %}
                <a href="javascript:restart()" class="dropdown-item">重启</a>
                <a href="javascript:update()" class="dropdown-item">更新</a>
              {% endif %}
            {% endif %}
            <a href="javascript:logout()" class="dropdown-item">注销</a>
          </div>
        </div>
      </div>
      <div class="collapse navbar-collapse" id="navbar-menu">
        <div class="my-2 my-md-0 flex-grow-1 flex-md-grow-0 order-first order-md-last d-lg-none">
          <div class="input-icon">
              <span class="input-icon-addon">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                     stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                  <circle cx="10" cy="10" r="7"/>
                  <line x1="21" y1="21" x2="15" y2="15"/>
                </svg>
              </span>
            <input type="text" value="" class="form-control theme-dark home_search_word" placeholder="搜索/订阅...">
          </div>
        </div>
        <ul class="navbar-nav pt-lg-3">
          {% if "我的媒体库" in UserPris %}
            <li class="nav-item">
              <a class="nav-link" href="javascript:void(0)" onclick="navmenu('index')">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                       stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                       stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <polyline points="5 12 3 12 12 3 21 12 19 12"/>
                    <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7"/>
                    <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6"/>
                  </svg>
                </span>
                <span class="nav-link-title">
                  开始
                </span>
              </a>
            </li>
          {% endif %}
          {% if "资源搜索" in UserPris %}
            <li class="nav-item">
              <a class="nav-link" href="javascript:void(0)" onclick="navmenu('search')">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search" width="24"
                       height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <circle cx="10" cy="10" r="7"></circle>
                    <line x1="21" y1="21" x2="15" y2="15"></line>
                  </svg>
                </span>
                <span class="nav-link-title">
                  资源搜索
                </span>
              </a>
            </li>
          {% endif %}
          {% if "推荐" in UserPris %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="false"
                 role="button" aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                       stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                       stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <path
                            d="M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873z"/>
                  </svg>
                </span>
                <span class="nav-link-title">
                  推荐
                </span>
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=hm')">
                  TMDB热门电影
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=ht')">
                  TMDB热门电视剧
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=nm')">
                  TMDB最新电影
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=nt')">
                  TMDB最新电视剧
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbom')">
                  正在热映
                  <span class="badge badge-sm bg-orange text-case ms-2">HOT</span>
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbnm')">
                  即将上映
                  <span class="badge badge-sm bg-green text-case ms-2">NEW</span>
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbhm')">
                  豆瓣热门电影
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbtop')">
                  豆瓣电影TOP250
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbht')">
                  豆瓣热门电视剧
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbdh')">
                  豆瓣热门动漫
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=dbzy')">
                  豆瓣热门综艺
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('recommend?t=bangumi')">
                  Bangumi每日放送
                </a>
              </div>
            </li>
          {% endif %}
          {% if "站点管理" in UserPris %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="false"
                 role="button" aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-server-2" width="24"
                       height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <rect x="3" y="4" width="18" height="8" rx="3"></rect>
                    <rect x="3" y="12" width="18" height="8" rx="3"></rect>
                    <line x1="7" y1="8" x2="7" y2="8.01"></line>
                    <line x1="7" y1="16" x2="7" y2="16.01"></line>
                    <path d="M11 8h6"></path>
                    <path d="M11 16h6"></path>
                  </svg>
                </span>
                <span class="nav-link-title">
                  站点管理
                </span>
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('site')">
                  站点维护
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('statistics')">
                  数据统计
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('brushtask')">
                  刷流任务
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('sitelist')">
                  站点资源
                </a>
              </div>
            </li>
          {% endif %}
          {% if "订阅管理" in UserPris %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="false"
                 role="button" aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                       stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                       stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <polyline points="9 11 12 14 20 6"/>
                    <path d="M20 12v6a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h9"/>
                  </svg>
                </span>
                <span class="nav-link-title">
                  订阅管理
                </span>
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('movie_rss')">
                  电影订阅
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('tv_rss')">
                  电视剧订阅
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('user_rss')">
                  自定义订阅
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('rss_calendar')">
                  订阅日历
                </a>
              </div>
            </li>
          {% endif %}
          {% if "下载管理" in UserPris %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="false"
                 role="button" aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-download" width="24"
                       height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"></path>
                    <polyline points="7 11 12 16 17 11"></polyline>
                    <line x1="12" y1="4" x2="12" y2="16"></line>
                  </svg>
                </span>
                <span class="nav-link-title">
                  下载管理
                </span>
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('downloading')">
                  正在下载
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('downloaded')">
                  近期下载
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('torrent_remove')">
                  自动删种
                </a>
              </div>
            </li>
          {% endif %}
          {% if "媒体整理" in UserPris %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="false"
                 role="button" aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-movie" width="24"
                       height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <rect x="4" y="4" width="16" height="16" rx="2"></rect>
                    <line x1="8" y1="4" x2="8" y2="20"></line>
                    <line x1="16" y1="4" x2="16" y2="20"></line>
                    <line x1="4" y1="8" x2="8" y2="8"></line>
                    <line x1="4" y1="16" x2="8" y2="16"></line>
                    <line x1="4" y1="12" x2="20" y2="12"></line>
                    <line x1="16" y1="8" x2="20" y2="8"></line>
                    <line x1="16" y1="16" x2="20" y2="16"></line>
                  </svg>
                </span>
                <span class="nav-link-title">
                  媒体整理
                </span>
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('mediafile')">
                  文件管理
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('unidentification')">
                  手动识别
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('history')">
                  历史记录
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('tmdbcache')">
                  TMDB缓存
                </a>
              </div>
            </li>
          {% endif %}
          {% if "服务" in UserPris %}
            <li class="nav-item">
              <a class="nav-link" href="javascript:void(0)" onclick="navmenu('service')">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                       stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                       stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <rect x="4" y="4" width="6" height="5" rx="2"/>
                    <rect x="4" y="13" width="6" height="7" rx="2"/>
                    <rect x="14" y="4" width="6" height="7" rx="2"/>
                    <rect x="14" y="15" width="6" height="5" rx="2"/>
                  </svg>
                </span>
                <span class="nav-link-title">
                  服务
                </span>
              </a>
            </li>
          {% endif %}
          {% if "系统设置" in UserPris %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="false"
                 role="button" aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-settings" width="24"
                       height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <path
                            d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z">
                    </path>
                    <circle cx="12" cy="12" r="3"></circle>
                  </svg>
                </span>
                <span class="nav-link-title">
                  设置
                </span>
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('basic')">
                  基础设置
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('users')">
                  用户管理
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('library')">
                  媒体库
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('directorysync')">
                  目录同步
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('notification')">
                  消息通知
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('filterrule')">
                  过滤规则
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('customwords')">
                  自定义识别词
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('indexer')">
                  索引器
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('downloader')">
                  下载器
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('mediaserver')">
                  媒体服务器
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('subtitle')">
                  字幕
                </a>
                <a class="dropdown-item" href="javascript:void(0)" onclick="navmenu('douban')">
                  豆瓣
                </a>
              </div>
            </li>
          {% endif %}
        </ul>
      </div>
    </div>
  </aside>
  <header class="navbar navbar-expand-md navbar-light d-none d-lg-flex d-print-none sticky-top">
    <div class="container-xl">
      <div class="navbar-nav flex-row order-md-last">
        <div class="nav-item d-none d-md-flex me-3">
          <div class="btn-list">
            <a href="https://github.com/jxxghp/nas-tools" class="btn" target="_blank" rel="noreferrer">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                   stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                <path
                        d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"/>
              </svg>
              Source code
            </a>
          </div>
        </div>
        <div class="d-none d-md-flex">
          <a href="?theme=dark" class="nav-link px-0 hide-theme-dark" title="暗黑风格" data-bs-placement="bottom">
            <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                 stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
              <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
              <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z"/>
            </svg>
          </a>
          <a href="?theme=light" class="nav-link px-0 hide-theme-light" title="明亮风格" data-bs-placement="bottom">
            <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                 stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
              <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
              <circle cx="12" cy="12" r="4"/>
              <path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7"/>
            </svg>
          </a>
          <div class="nav-item dropdown d-none d-md-flex me-3">
            <a href="#" class="nav-link px-0" data-bs-toggle="dropdown" tabindex="-1" aria-label="新版本提示"
               id="new_version_tip" style="display:none">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                   stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                <path d="M10 5a2 2 0 0 1 4 0a7 7 0 0 1 4 6v3a4 4 0 0 0 2 3h-16a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6"/>
                <path d="M9 17v1a3 3 0 0 0 6 0v-1"/>
              </svg>
              <span class="badge bg-red"></span>
            </a>
            <div class="dropdown-menu dropdown-menu-arrow dropdown-menu-end dropdown-menu-card">
              <div class="card">
                <div class="card-header">
                  <h3 class="card-title">新版本</h3>
                </div>
                <div class="list-group list-group-flush list-group-hoverable">
                  <div class="list-group-item">
                    <div class="row align-items-center">
                      <div class="col-auto"><span class="status-dot status-dot-animated bg-red d-block"></span></div>
                      <div class="col text-truncate">
                        <div class="d-block text-muted text-truncate mt-n1" id="new_version_info">
                        </div>
                      </div>
                      {% if SystemFlag > 0 and "系统设置" in UserPris %}
                        <div class="col-auto">
                          <a href="javascript:update(NewVersion)" class="list-group-item-actions" title="升级版本">
                            <svg xmlns="http://www.w3.org/2000/svg"
                                 class="icon icon-tabler icon-tabler-arrow-big-up-lines" width="24" height="24"
                                 viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                                 stroke-linecap="round" stroke-linejoin="round">
                              <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                              <path
                                      d="M9 12h-3.586a1 1 0 0 1 -.707 -1.707l6.586 -6.586a1 1 0 0 1 1.414 0l6.586 6.586a1 1 0 0 1 -.707 1.707h-3.586v3h-6v-3z">
                              </path>
                              <path d="M9 21h6"></path>
                              <path d="M9 18h6"></path>
                            </svg>
                          </a>
                        </div>
                      {% endif %}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="nav-item dropdown">
          <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown"
             aria-label="Open user menu">
              <span class="avatar avatar-sm">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user" width="24" height="24"
                     viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                     stroke-linejoin="round">
                  <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                  <circle cx="12" cy="7" r="4"></circle>
                  <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"></path>
                </svg>
              </span>
            <div class="d-none d-xl-block ps-2">
              <div>{{ UserName }}</div>
            </div>
          </a>
          <div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
            {% if "系统设置" in UserPris %}
              <a class="dropdown-item" data-bs-toggle="offcanvas" href="#offcanvasEnd" role="button"
                 aria-controls="offcanvasEnd">消息中心</a>
              <a class="dropdown-item" href="javascript:show_logging_modal()" role="button">实时日志</a>
              <div class="dropdown-divider"></div>
              {% if SystemFlag > 0 %}
                <a href="javascript:restart()" class="dropdown-item">重启</a>
                <a href="javascript:update()" class="dropdown-item">更新</a>
              {% endif %}
            {% endif %}
            <a href="javascript:logout()" class="dropdown-item">注销</a>
          </div>
        </div>
      </div>
      <div class="collapse navbar-collapse">
        <div>
          <div class="input-icon">
              <span class="input-icon-addon">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                     stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                  <desc>Download more icon variants from https://tabler-icons.io/i/search</desc>
                  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                  <circle cx="10" cy="10" r="7"/>
                  <line x1="21" y1="21" x2="15" y2="15"/>
                </svg>
              </span>
            <input type="text" value="" class="form-control home_search_word" placeholder="搜索/订阅…"
                   aria-label="资源搜索/订阅">
          </div>
        </div>
      </div>
    </div>
  </header>
  <div class="page-wrapper" id="page_wrapper">
    <div id="page_content"></div>
    <footer class="footer footer-transparent d-print-none" style="padding: 0;">
      <div class="container-xl">
        <div class="row text-center align-items-center flex-row-reverse">
          <div class="col-12 col-lg-auto mt-3 mt-lg-0">
            <ul class="list-inline list-inline-dots mb-0">
              <li class="list-inline-item">
                Copyright &copy; 2022
                <a href="." class="link-secondary">NAStool</a>.
                All rights reserved.
              </li>
              <li class="list-inline-item">
                {{ AppVersion }}
              </li>
            </ul>
          </div>
        </div>
      </div>
    </footer>
  </div>
</div>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasEnd" aria-labelledby="消息中心">
  <div class="offcanvas-header">
    <h2 class="offcanvas-title" id="offcanvasEndLabel">消息中心</h2>
    <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  </div>
  <div class="offcanvas-body" style="padding:0.5rem 0.5rem;">
    <div class="list-group list-group-flush" id="system-messages">
    </div>
    <div class="mt-3" align="center">
      <button class="btn btn-primary" type="button" data-bs-dismiss="offcanvas">
        关闭
      </button>
    </div>
  </div>
</div>
<!-- 等待框 -->
<div class="modal" id="modal-wait" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-full-width modal-dialog-centered" role="document">
    <div class="spinner-border text-primary m-auto"></div>
  </div>
</div>
<!-- 进度框 -->
<div class="modal modal-blur" id="modal-process" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-md modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="card border-0" style="overflow:hidden">
        <div class="progress rounded-0">
          <div class="progress-bar progress-bar-striped progress-bar-animated" id="modal_process_bar"
               style="width: 0%" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
        </div>
        <div class="card-body text-center">
          <h3 class="card-title strong" id="modal_process_title">
          </h3>
          <small class="text-muted" id="modal_process_text">请稍候...</small>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 危险确认提示框 -->
<div class="modal modal-blur fade" id="system-confirm-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
    <div class="modal-content">
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      <div class="modal-status bg-danger"></div>
      <div class="modal-body text-center py-4">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-danger icon-lg" width="24" height="24"
             viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
             stroke-linejoin="round">
          <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
          <path d="M12 9v2m0 4v.01"/>
          <path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75"/>
        </svg>
        <h3>确认</h3>
        <div class="text-muted text-wrap" id="system_confirm_message" style="overflow: hidden">是否确定？</div>
      </div>
      <div class="modal-footer">
        <div class="w-100">
          <div class="row">
            <div class="col">
              <a href="#" class="btn w-100" data-bs-dismiss="modal">
                取消
              </a>
            </div>
            <div class="col">
              <button class="btn btn-danger w-100" id="system_confirm_btn">
                确定
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 成功带后续操作提示框 -->
<div class="modal modal-blur fade" id="system-success-action-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
    <div class="modal-content">
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      <div class="modal-status bg-success"></div>
      <div class="modal-body text-center py-4">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-green icon-lg" width="24" height="24"
             viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
             stroke-linejoin="round">
          <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
          <circle cx="12" cy="12" r="9"/>
          <path d="M9 12l2 2l4 -4"/>
        </svg>
        <h3>成功</h3>
        <div class="text-muted text-wrap" id="system_success_action_message" style="overflow: hidden">操作成功！</div>
      </div>
      <div class="modal-footer">
        <div class="w-100">
          <div class="row">
            <div class="col">
              <a href="#" class="btn w-100" data-bs-dismiss="modal">
                关闭
              </a>
            </div>
            <div class="col" id="system_success_action_div">
              <button class="btn btn-success w-100" id="system_success_action_btn">
                确定
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 询问框 -->
<div class="modal modal-blur fade" id="system-ask-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-body">
        <div class="modal-title">询问</div>
        <div id="system_ask_message" class="text-wrap" style="overflow: hidden">是否执行？</div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-link link-secondary me-auto" data-bs-dismiss="modal">取消</button>
        <button type="button" class="btn btn-danger" id="system_ask_btn">确定</button>
      </div>
    </div>
  </div>
</div>
<!-- 成功提示 -->
<div class="modal modal-blur fade" id="system-success-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
    <div class="modal-content">
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      <div class="modal-status bg-success"></div>
      <div class="modal-body text-center py-4">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-green icon-lg" width="24" height="24"
             viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
             stroke-linejoin="round">
          <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
          <circle cx="12" cy="12" r="9"/>
          <path d="M9 12l2 2l4 -4"/>
        </svg>
        <h3>成功</h3>
        <div class="text-muted text-wrap" id="system_success_message" style="overflow: hidden">成功！</div>
      </div>
      <div class="modal-footer">
        <div class="w-100">
          <div class="row">
            <div class="col">
              <a href="javascript:void(0)" id="system_success_modal_btn" class="btn btn-success w-100"
                 data-bs-dismiss="modal">
                确定
              </a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 失败提示 -->
<div class="modal modal-blur fade" id="system-fail-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
    <div class="modal-content">
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      <div class="modal-status bg-warning"></div>
      <div class="modal-body text-center py-4">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-warning icon-lg" width="24" height="24"
             viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
             stroke-linejoin="round">
          <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
          <path d="M12 9v2m0 4v.01"/>
          <path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75"/>
        </svg>
        <h3>失败</h3>
        <div class="text-muted text-wrap" id="system_fail_message" style="overflow:hidden">失败！</div>
      </div>
      <div class="modal-footer">
        <div class="w-100">
          <div class="row">
            <div class="col">
              <a href="#" id="system_fail_modal_btn" class="btn btn-warning w-100" data-bs-dismiss="modal">
                确定
              </a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 媒体详情 -->
<div class="modal modal-blur fade" id="system-media-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="card">
        <div class="ribbon ribbon-top ribbon-bookmark bg-purple" id="system_media_vote"></div>
        <div class="row row-0">
          <div class="col-3 d-none d-lg-block">
            <img id="system_media_poster" src="" onerror="this.src='../static/img/no-image.png'"
                 class="w-100 h-100 object-cover">
          </div>
          <div class="col">
            <div class="card-body">
              <h4 class="card-title mb-3">
                <a id="system_media_name_link" href="#" target="_blank"><strong
                        id="system_media_name"></strong></a><br/>
                <span class="text-muted" id="system_release_date"></span>
              </h4>
              <div class="text-muted mb-3" id="system_media_overview">
              </div>
              <div id="system_sites_info"></div>
            </div>
          </div>
        </div>
        <div class="d-flex">
          <a href="#" target="_blank" class="card-btn" id="system_media_url_btn">
            详情
          </a>
          <a href="javascript:void(0)" data-bs-toggle="dropdown" class="dropdown-toggle card-btn"
             id="system_media_rss_btn">
            订阅
          </a>
          <div class="dropdown-menu" id="system_media_rss_dropdown"></div>
          <a href="javascript:void(0)" class="card-btn" id="system_media_search_btn"
             style="border-left:1px solid var(--tblr-border-color)">
            搜索
          </a>
          <a href="javascript:void(0)" class="card-btn" id="system_media_refresh_btn"
             style="border-left:1px solid var(--tblr-border-color)">
            刷新
          </a>
          <a href="javascript:void(0)" class="card-btn d-none d-md-block" data-bs-dismiss="modal">
            关闭
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 实时日志 -->
<div class="modal modal-blur fade" id="modal-logging" tabindex="-1" role="dialog" aria-hidden="true"
     data-bs-backdrop="static" data-bs-keyboard="false">
  <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">实时日志</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
                id="logging_close_head"></button>
      </div>
      <div id="logging_table" class="table-responsive" style="overflow-y: auto; max-height: 60rem;">
      <table class="table table-vcenter card-table table-hover table-striped">
        <thead>
          <tr>
            <th class="w-3">时间</th>
            <th class="w-3">来源</th>
            <th>内容</th>
          </tr>
        </thead>
        <tbody id="logging_content" class="table-tbody">
        </tbody>
      </table>
      </div>
      <div class="modal-footer">
        <a href="javascript:pause_logging()" class="btn btn-link me-auto" id="logging_stop_btn">
          暂停
        </a>
        <button type="button" class="btn btn-primary" data-bs-dismiss="modal" id="logging_close_btn">关闭</button>
      </div>
    </div>
  </div>
</div>
<!-- 订阅季 -->
<div class="modal modal-blur fade" id="system-rss-seasons" tabindex="-1" role="dialog" aria-hidden="true"
     data-bs-backdrop="static" data-bs-keyboard="false">
  <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">选择订阅季</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col">
            <div class="mb-3">
              <div class="form-selectgroup" id="system_rss_seasons_group">
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <a href="javascript:void(0)" id="system_rss_seasons_btn" class="btn btn-primary">确定</a>
      </div>
    </div>
  </div>
</div>
<!-- 手动订阅 -->
<div class="modal modal-blur fade" id="modal-manual-rss" tabindex="-1" role="dialog" aria-hidden="true"
     data-bs-backdrop="static" data-bs-keyboard="false">
  <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="rss_modal_title">新增订阅</h5>
        <input type="hidden" id="rss_id">
        <input type="hidden" id="rss_type">
        <input type="hidden" id="rss_tmdbid">
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-8">
            <div class="mb-3">
              <label class="form-label required">标题</label>
              <input type="text" value="" id="rss_name" class="form-control" placeholder="标题">
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label required">年份</label>
              <input type="text" value="" id="rss_year" class="form-control" placeholder="年份">
            </div>
          </div>
        </div>
        <div class="row" id="rss_tv_season_div">
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label required">季</label>
              <select class="form-select" id="rss_season">
                <option value="" selected>请选择</option>
              </select>
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">总集数 <span class="form-help"
                                                     title="可留空应用TMDB剧集信息"
                                                     data-bs-toggle="tooltip">?</span></label>
              <input type="text" value="" id="rss_total_ep" class="form-control" placeholder="总集数">
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">开始订阅集数</label>
              <input type="text" value="" id="rss_current_ep" class="form-control" placeholder="开始订阅集数">
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-xl-4">
            <div class="mb-3">
              <label class="form-check form-switch">
                <input class="form-check-input" type="checkbox" id="fuzzy_match"
                       onclick="javascript:change_match_check(this)">
                <span class="form-check-label">模糊匹配 <span class="form-help"
                                                              title="开启后不检查TMDB是否有媒体信息，只要种子名称、标题、年份任一匹配关键字即会下载，此时标题可以配置正则表达式实现模糊匹配"
                                                              data-bs-toggle="tooltip">?</span></span>
              </label>
            </div>
          </div>
          <div class="col-xl-4">
            <div class="mb-3">
              <label class="form-check form-switch">
                <input class="form-check-input" type="checkbox" id="over_edition"
                       onclick="javascript:change_over_edition_check(this)">
                <span class="form-check-label">洗版 <span class="form-help"
                                                          title="开启后RSS不检查媒体库是否已存在，命中即会下载"
                                                          data-bs-toggle="tooltip">?</span></span>
              </label>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label">质量</label>
              <select class="form-select" id="rss_restype">
                <option value="" selected>全部</option>
                {% for Restype in RestypeDict %}
                  <option value="{{ Restype }}">{{ Restype }}</option>
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label">分辨率</label>
              <select class="form-select" id="rss_pix">
                <option value="" selected>全部</option>
                {% for Pix in PixDict %}
                  <option value="{{ Pix }}">{{ Pix }}</option>
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label">制作组/字幕组</label>
              <input type="text" value="" id="rss_team" class="form-control" placeholder="支持正则表达式">
            </div>
          </div>
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label">过滤规则 <span class="form-help"
                                                       title="质量、分辨率与过滤规则为“与”的关系，过滤规则不选择时将使用站点的过滤规则，站点也未设置过滤规则时将使用默认过滤规则"
                                                       data-bs-toggle="tooltip">?</span></label>
              <select class="form-select" id="rss_rule">
              </select>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">下载设置</label>
              <select class="form-select" id="rss_download_setting"
                      onchange="refresh_savepath_select('rss_save_path', true, $(this).val())">
              </select>
            </div>
          </div>
          <div class="col-lg-8">
            <div class="mb-3">
              <label class="form-label">保存路径</label>
              <select class="form-select" id="rss_save_path" aria-label="保存目录">
              </select>
            </div>
          </div>
        </div>
        <div class="row rss_sites_container" id="rss_sites_div">
          <div class="mb-3">
            <label class="form-label">订阅站点</label>
            <div class="form-selectgroup" id="rss_sites_group">
            </div>
          </div>
        </div>
        <div class="row rss_sites_container" id="rss_search_sites_div">
          <div class="mb-3">
            <label class="form-label">搜索站点</label>
            <div class="form-selectgroup" id="rss_search_sites_group">
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <a href="javascript:rss_sites_select()" class="btn btn-link me-auto" id="rss_sites_select_btn">
          取消全选
        </a>
        <a href="#" class="btn btn-link text-red" id="rss_delete_btn">
          取消订阅
        </a>
        <a href="javascript:add_rss_manual()" id="rss_add_btn" class="btn btn-primary">确定</a>
      </div>
    </div>
  </div>
</div>
<!-- 手动识别 -->
<div class="modal modal-blur fade" id="modal-media-identification" tabindex="-1" role="dialog" aria-hidden="true"
     data-bs-backdrop="static" data-bs-keyboard="false">
  <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="rename_header">手动识别</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row" id="rename_path_div">
          <div class="col-lg-9">
            <div class="mb-3">
              <label class="form-label required">路径</label>
              <input type="text" id="rename_path" class="form-control" readonly>
              <input type="hidden" id="rename_manual_type">
              <input type="hidden" id="unknown_id">
              <input type="hidden" id="transferlog_id" class="form-control">
              <div class="invalid-feedback" id="rename_retmsg"></div>
            </div>
          </div>
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label required">转移方式</label>
              <select id="rename_syncmod_manual" class="form-select">
                <option value="link" {% if SyncMod=="link" %} selected="selected" {% endif %}>硬链接</option>
                <option value="softlink" {% if SyncMod=="softlink" %} selected="selected" {% endif %}>软链接</option>
                <option value="copy" {% if SyncMod=="copy" %} selected="selected" {% endif %}>复制</option>
                <option value="move" {% if SyncMod=="move" %} selected="selected" {% endif %}>移动</option>
                <option value="rclonecopy" {% if SyncMod=="rclonecopy" %} selected="selected" {% endif %}>Rclone复制
                </option>
                <option value="rclone" {% if SyncMod=="rclone" %} selected="selected" {% endif %}>Rclone移动</option>
                <option value="miniocopy" {% if SyncMod=="miniocopy" %} selected="selected" {% endif %}>Minio复制
                </option>
                <option value="minio" {% if SyncMod=="minio" %} selected="selected" {% endif %}>Minio移动</option>
              </select>
            </div>
          </div>
        </div>
        <div class="mb-3" id="rename_inpath_div">
          <label class="form-label required">输入路径</label>
          <input type="text" id="rename_inpath" class="form-control filetree-folders-only"
                 placeholder="需要转移的目录或文件"
                 autocomplete="off">
          <div class="invalid-feedback" id="rename_udf_retmsg"></div>
        </div>
        <div class="row" id="rename_outpath_div">
          <div class="col-lg-9">
            <div class="mb-3">
              <label class="form-label">输出路径</label>
              <input type="text" id="rename_outpath" class="form-control filetree-folders-only"
                     placeholder="转移后文件存储路径，留空则转移至媒体库" autocomplete="off">
            </div>
          </div>
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label required">转移方式</label>
              <select id="rename_syncmod_customize" class="form-select">
                <option value="link" {% if SyncMod=="link" %} selected="selected" {% endif %}>硬链接</option>
                <option value="softlink" {% if SyncMod=="softlink" %} selected="selected" {% endif %}>软链接</option>
                <option value="copy" {% if SyncMod=="copy" %} selected="selected" {% endif %}>复制</option>
                <option value="move" {% if SyncMod=="move" %} selected="selected" {% endif %}>移动</option>
                <option value="rclonecopy" {% if SyncMod=="rclonecopy" %} selected="selected" {% endif %}>Rclone复制
                </option>
                <option value="rclone" {% if SyncMod=="rclone" %} selected="selected" {% endif %}>Rclone移动</option>
                <option value="miniocopy" {% if SyncMod=="miniocopy" %} selected="selected" {% endif %}>Minio复制
                </option>
                <option value="minio" {% if SyncMod=="minio" %} selected="selected" {% endif %}>Minio移动</option>
              </select>
            </div>
          </div>
        </div>
        <label class="form-label">类型</label>
        <div class="form-selectgroup-boxes row mb-3">
          <div class="col-lg-4">
            <div class="mb-1">
              <label class="form-selectgroup-item">
                <input type="radio" id="rename_type_mov" name="rename_type" value="MOV" class="form-selectgroup-input"
                       checked>
                <span class="form-selectgroup-label d-flex align-items-center p-3">
                    <span class="me-3">
                      <span class="form-selectgroup-check"></span>
                    </span>
                    <span class="form-selectgroup-label-content">
                      <span class="form-selectgroup-title strong mb-1">电影</span>
                    </span>
                  </span>
              </label>
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-1">
              <label class="form-selectgroup-item">
                <input type="radio" id="rename_type_tv" name="rename_type" value="TV" class="form-selectgroup-input">
                <span class="form-selectgroup-label d-flex align-items-center p-3">
                    <span class="me-3">
                      <span class="form-selectgroup-check"></span>
                    </span>
                    <span class="form-selectgroup-label-content">
                      <span class="form-selectgroup-title strong mb-1">电视剧</span>
                    </span>
                  </span>
              </label>
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-1">
              <label class="form-selectgroup-item">
                <input type="radio" id="rename_type_anime" name="rename_type" value="ANIME"
                       class="form-selectgroup-input">
                <span class="form-selectgroup-label d-flex align-items-center p-3">
                    <span class="me-3">
                      <span class="form-selectgroup-check"></span>
                    </span>
                    <span class="form-selectgroup-label-content">
                      <span class="form-selectgroup-title strong mb-1">动漫</span>
                    </span>
                  </span>
              </label>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">TMDB ID</label>
              <input type="text" id="rename_tmdb" class="form-control" placeholder="留空自动识别">
            </div>
          </div>
          <div class="col-lg-4" id="rename_season_div">
            <div class="mb-3">
              <label class="form-label">季</label>
              <select class="form-select" id="rename_season">
                <option value="" selected>请选择</option>
              </select>
            </div>
          </div>
          <div class="col-lg-4" id="rename_min_filesize_div">
            <div class="mb-3">
              <label class="form-label">最小文件大小</label>
              <input type="text" id="rename_min_filesize" class="form-control" placeholder="最小文件大小(MB)">
            </div>
          </div>
          <div class="col-lg-12" id="rename_episode_div">
            <div class="mb-3">
              <label class="form-label">集数定位 <span class="form-help"
                                                       title="3个都不填，用默认识别<br>{ep}: 标定集数位置，例如：<br>&nbsp;&nbsp;&nbsp;&nbsp;(BD)十二国記 第45話「東の海神 西の滄海 五章」(1440x1080 x264-10bpp flac).mkv<br>&nbsp;&nbsp;&nbsp;&nbsp;(BD)十二国記 第32話「風の万里 黎明の空　九章」(1440x1080 x264-10bpp flac).mkv<br>&nbsp;&nbsp;&nbsp;&nbsp;此处可以填(BD)十二国記 第{ep}話{a}(1440x1080 x264-10bpp flac).mkv ep表示集，a表示理解成一个变量，随意用一个变量表示，如果没有变化的部分，只标定ep就行<br>start_ep[, end_ep], 裁定范围， 如果输入是文件，输出就是单个文件，如果输入是目录，输出可以根据填的值批量识别<br>&nbsp;&nbsp;&nbsp;&nbsp;例如 '1' 表示第一集, '2,4' 只取第2集到第4集，'1-2'表示第1-2集，此选项优先级最高<br>offset: 集数偏移, 例如ep定位出集数是11, 实际是第一集, 此处填-10, 以应付多季合集的场景 "
                                                       data-bs-toggle="tooltip" data-bs-html="true">?</span></label>
              <div class="row">
                <div class="col-4">
                  <input type="text" id="rename_episode" class="form-control" placeholder="{ep}.mp4">
                </div>
                <div class="col-4">
                  <input type="text" id="rename_episode_details" class="form-control"
                         placeholder="start_ep[, end_ep] 可选">
                </div>
                <div class="col-4">
                  <input type="text" id="rename_episode_offset" class="form-control" placeholder="offset, 可选">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-link me-auto" data-bs-dismiss="modal">取消</button>
        <button type="button" id="identification_action_btn" class="btn btn-primary"
                onclick="manual_media_transfer()">转移
        </button>
      </div>
    </div>
  </div>
</div>
<!-- 手动下载 -->
<div class="modal modal-blur fade" id="modal-search-download" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-md modal-dialog-centered" role="document">
    <input type="hidden" id="search_download_id">
    <input type="hidden" id="search_download_name">
    <div class="modal-content">
      <div class="modal-body">
        <div class="modal-title" id="search_download_message">添加下载</div>
        <div class="row mt-3">
          <div class="col-md">
            <div class="form-floating mb-1">
              <select class="form-select" id="search_download_setting" aria-label="下载设置" onchange="refresh_download_setting_dirs()">
              </select>
              <label for="floatingSelect">下载设置</label>
            </div>
          </div>
          <div class="col-md">
            <div class="form-floating mb-1">
              <select class="form-select" id="search_download_dir" aria-label="保存目录">
              </select>
              <label for="floatingSelect">保存目录</label>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-link link-secondary me-auto" data-bs-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" id="search_download_btn" title="自动选择目录下载">
          下载
        </button>
      </div>
    </div>
  </div>
</div>
<script src="../static/js/libs/list.min.js"></script>
<script src="../static/js/jquery-3.3.1.min.js"></script>
<script src="../static/js/tabler.min.js"></script>
<script src="../static/js/demo.min.js"></script>
<script src="../static/js/util.js"></script>
<script src="../static/js/apexcharts.min.js"></script>
<script src="../static/js/echarts.min.js"></script>
<script src="../static/js/numeral.min.js"></script>
<script src="../static/js/fullcalendar.min.js"></script>
<script src="../static/js/locales/zh-cn.js"></script>
<script src="../static/js/jquery.filetree.js"></script>
<script src="../static/js/dropzone-min.js"></script>
<script src="../static/js/dom-to-image.min.js"></script>
<script src="../static/js/FileSaver.min.js"></script>

<!-- 提示弹窗 -->
<script type="text/javascript">
  //是否触摸屏设备
  function is_touch_device() {
    return 'ontouchstart' in window;
  }

  //显示全局加载框
  function show_wait_process(blur) {
    if (blur) {
      $('#modal-wait').addClass('modal-blur');
    } else {
      $('#modal-wait').removeClass('modal-blur');
    }
    $("#modal-wait").modal("show");
  }

  //关闭全局加载框
  function hide_wait_process() {
    $("#modal-wait").modal("hide");
  }

  //刷新进度及文件
  let refresh_process_flag = false;
  let refresh_fail_count = 0;

  function refresh_process() {
    if (!refresh_process_flag) {
      return;
    }
    ajax_post("refresh_process", {type: "search"}, function (ret) {
      if (ret.code === 0 && ret.value <= 100) {
        $("#modal_process_bar").attr("style", "width: " + ret.value + "%").attr("aria-valuenow", ret.value);
        $("#modal_process_text").text(ret.text);
      } else {
        refresh_fail_count = refresh_fail_count + 1;
      }
      if (refresh_fail_count < 5) {
        setTimeout("refresh_process()", 200);
      }
    });
  }

  //显示全局进度框
  function show_refresh_process(title) {
    if (title) {
      $("#modal_process_title").text(title);
    } else {
      $("#modal_process_title").hide();
    }
    $("#modal_process_bar").attr("style", "width: 0%").attr("aria-valuenow", 0);
    $("#modal_process_text").text("请稍候...");
    $("#modal-process").modal("show");
    //刷新进度
    refresh_process_flag = true;
    refresh_fail_count = 0;
    refresh_process();
  }

  //关闭全局进度框
  function hide_refresh_process() {
    refresh_process_flag = false;
    $("#modal-process").modal("hide");
  }

  //显示确认提示框
  function show_confirm_modal(title, func) {
    $("#system_confirm_message").text(title);
    $("#system_confirm_btn").unbind('click').click(func);
    $("#system-confirm-modal").modal("show");
  }

  //隐藏确认提示框
  function hide_confirm_modal() {
    $("#system-confirm-modal").modal("hide");
  }

  //显示询问提示框
  function show_ask_modal(title, func) {
    $("#system_ask_message").text(title);
    $("#system_ask_btn").unbind('click').click(func);
    $("#system-ask-modal").modal("show");
  }

  //隐藏询问提示框
  function hide_ask_modal() {
    $("#system-ask-modal").modal("hide");
  }

  //显示成功提示
  function show_success_modal(title, func) {
    $("#system_success_message").text(title);
    if (func) {
      $("#system_success_modal_btn").unbind('click').click(func);
    } else {
      $("#system_success_modal_btn").unbind('click');
    }
    $("#system-success-modal").modal("show");
  }

  //显示失败提示
  function show_fail_modal(title, func) {
    $("#system_fail_message").text(title);
    if (func) {
      $("#system_fail_modal_btn").unbind('click').click(func);
    } else {
      $("#system_fail_modal_btn").unbind('click');
    }
    $("#system-fail-modal").modal("show");
  }
</script>

<!-- 媒体弹窗 -->
<script type="text/javascript">
  //显示媒体详情
  function show_mediainfo_modal(rtype, name, year, tmdbid, page, rssid, auto_search) {
    let doubanid;
    show_wait_process();
    if (tmdbid.startsWith("DB:")) {
      doubanid = tmdbid.replace("DB:", "");
      tmdbid = "";
    } else if (isNaN(tmdbid)) {
      doubanid = "";
      tmdbid = "";
    } else {
      doubanid = "";
    }
    if (!page) {
      page = "";
    }
    if (!rssid) {
      rssid = "";
    }
    ajax_post("media_info", {
      "id": tmdbid,
      "title": name,
      "year": year,
      "type": rtype,
      "doubanid": doubanid,
      "page": page,
      "rssid": rssid
    }, function (ret) {
      hide_wait_process();
      if (ret.code === 0) {
        if (auto_search) {
          search_mediainfo_media(ret.tmdbid, ret.doubanid, ret.title, ret.type_str);
          return
        }
        //显示信息
        $("#system_media_name").text(ret.title);
        $("#system_release_date").text(ret.release_date)
        if (ret.poster_path) {
          $("#system_media_poster").attr("src", ret.poster_path);
        } else {
          $("#system_media_poster").attr("src", "../static/img/no-image.png");
        }
        if (ret.overview && ret.overview.length > 200) {
          $("#system_media_overview").text(ret.overview.substr(0, 200) + " ...");
        } else {
          $("#system_media_overview").text(ret.overview);
        }
        if (!ret.vote_average || ret.vote_average == "0") {
          $("#system_media_vote").hide();
        } else {
          $("#system_media_vote").text(ret.vote_average).show();
        }
        //订阅按钮、搜索按钮
        if ($("#system_media_rss_dropdown").hasClass("show")) {
          $("#system_media_rss_btn").dropdown("toggle");
        }
        //先隐藏所有按钮，有需要再显示
        $("#system_media_rss_btn").hide();
        $("#system_media_search_btn").hide();
        $("#system_media_refresh_btn").hide();
        $("#system_media_url_btn").hide();
        if (ret.rssid) {
          //取消订阅按钮
          $("#system_media_rss_btn").text("取消订阅")
              .removeAttr("data-bs-toggle")
              .removeClass("dropdown-toggle")
              .attr("href", 'javascript:remove_rss_media("' + ret.title + '","' + ret.year + '","' + ret.type + '","' + ret.rssid + '","' + ret.page + '")')
              .show();
          //搜索按钮
          $("#system_media_search_btn").text("搜索")
              .attr("href", 'javascript:search_mediainfo_media("' + ret.tmdbid + '", "' + ret.doubanid + '", "' + ret.title + '", "' + ret.type_str + '")')
              .show();
          //刷新和编辑按钮
          if (ret.page.startsWith("movie_rss") || ret.page.startsWith("tv_rss")) {
            //编辑
            $("#system_media_url_btn").text("编辑")
                .removeAttr("target")
                .attr("href", "javascript:show_edit_rss_media_modal('" + ret.rssid + "', '" + ret.type_str + "')")
                .show();
            //刷新
            $("#system_media_refresh_btn").text("刷新")
                .attr("href", 'javascript:refresh_rss_media("' + ret.type + '","' + ret.rssid + '","' + ret.page + '")')
                .show();
          } else {
            //详情按钮
            $("#system_media_url_btn").text("详情")
                .attr("target", "_blank")
                .attr("href", ret.link_url)
                .show();
          }
        } else {
          //详情按钮
          $("#system_media_url_btn").text("详情")
              .attr("target", "_blank")
              .attr("href", ret.link_url)
              .show();
          //订阅按钮
          $("#system_media_rss_btn").text("订阅");
          $("#system_media_rss_dropdown").empty();
          if (ret.seasons.length === 0) {
            $("#system_media_rss_btn").removeAttr("data-bs-toggle")
                .removeClass("dropdown-toggle")
                .attr("href", 'javascript:add_rss_media("' + ret.title + '","' + ret.year + '","' + ret.type + '","' + ret.tmdbid + '","' + ret.doubanid + '","' + ret.page + '","")')
          } else {
            $("#system_media_rss_btn").prop("data-bs-toggle", "dropdown")
                .addClass("dropdown-toggle")
                .attr("href", 'javascript:$("#system_media_rss_btn").dropdown("toggle")')
            //订阅季的下拉框
            for (let i = 0; i < ret.seasons.length; i++) {
              $("#system_media_rss_dropdown").append('<a class="dropdown-item" href=\'javascript:add_rss_media("' + ret.title + '","' + ret.year + '","' + ret.type + '","' + ret.tmdbid + '","' + ret.doubanid + '","' + ret.page + '","' + ret.seasons[i].num + '")\'>' + ret.seasons[i].text + '</a>');
            }
          }
          $("#system_media_rss_btn").show();
          //搜索按钮
          $("#system_media_search_btn").text("搜索")
              .attr("href", 'javascript:search_mediainfo_media("' + ret.tmdbid + '", "' + ret.doubanid + '", "' + ret.title + '", "' + ret.type_str + '")')
              .show();
        }
        $("#system_media_name_link").attr("href", ret.link_url);
        //弹窗
        $("#system-media-modal").modal("show");
      } else if (ret.code === 1) {
        if (ret.rssid) {
          show_edit_rss_media_modal(ret.rssid, ret.type_str);
        } else {
          show_fail_modal(`${name} 未查询到TMDB媒体信息！`);
        }
      }
    });
  }

  //隐藏媒体详情
  function hide_mediainfo_modal() {
    $("#system-media-modal").modal("hide");
  }

  //新增订阅
  function add_rss_media(name, year, type, tmdbid, doubanid, page, season, func) {
    hide_mediainfo_modal();
    let data = {
      "name": name,
      "type": type,
      "year": year,
      "doubanid": doubanid,
      "tmdbid": tmdbid,
      "page": page,
      "season": season
    };
    show_wait_process();
    ajax_post("add_rss_media", data, function (ret) {
      hide_wait_process();
      if (ret.code === 0) {
        if (ret.page) {
          navmenu(ret.page);
        } else {
          if (func) {
            func();
          }
          show_rss_success_modal(ret.rssid, type, name + " 添加订阅成功！")
        }
      } else {
        show_fail_modal(`${ret.name} 添加订阅失败：${ret.msg}！`);
      }
    });
  }

  // 取消订阅
  function remove_rss_media(name, year, type, rssid, page, tmdbid, func) {
    hide_mediainfo_modal();
    let data = {"name": name, "type": type, "year": year, "rssid": rssid, "page": page, "tmdbid": tmdbid};
    ajax_post("remove_rss_media", data, function (ret) {
      if (func) {
        func();
      } else if (ret.page) {
        navmenu(ret.page);
      } else {
        show_success_modal(ret.name + " 已从订阅中移除！");
      }
    });
  }

  // 刷新订阅
  function refresh_rss_media(type, rssid, page) {
    hide_mediainfo_modal();
    ajax_post("refresh_rss", {"type": type, "rssid": rssid, "page": page}, function (ret) {
      if (ret.page) {
        navmenu(ret.page);
      } else {

      }
    });
  }

  //显示订阅季选择框
  function show_rss_seasons_modal(name, year, type, tmdbid, doubanid, seasons, func) {
    $("#system_rss_seasons_group").empty();
    for (var i = 0; i < seasons.length; i++) {
      $("#system_rss_seasons_group").append('<label class="form-selectgroup-item"><input type="checkbox" name="system_rss_season" value="' + seasons[i].num + '" class="form-selectgroup-input"><span class="form-selectgroup-label">' + seasons[i].text + '</span></label>');
    }
    $("#system_rss_seasons_btn").unbind('click').click(function () {
      $("#system-rss-seasons").modal('hide');
      let i = 0;
      let rss_seasons = [];
      $("input[name='system_rss_season']").each(function () {
        if ($(this).prop("checked")) {
          rss_seasons[i] = $(this).val();
          i = i + 1;
        }
      });
      if (rss_seasons.length > 0) {
        add_rss_media(name, year, type, tmdbid, doubanid, '', rss_seasons, func);
      }
    });
    $("#system-rss-seasons").modal('show');
  }

  //搜索
  function search_mediainfo_media(tmdbid, doubanid, title, typestr) {
    hide_mediainfo_modal();
    if (!tmdbid && doubanid) {
      tmdbid = "DB:" + doubanid;
    }
    const param = {"tmdbid": tmdbid, "search_word": title, "media_type": typestr};
    show_refresh_process("正在搜索 " + title + " ...");
    ajax_post("search", param, function (ret) {
      hide_refresh_process();
      if (ret.code === 0) {
        navmenu('search?s=' + title);
      } else {
        show_fail_modal(ret.msg);
      }
    });
  }

  //新增订阅
  function add_rss_manual() {
    const mtype = $("#rss_type").val();
    const name = $("#rss_name").val();
    const year = $("#rss_year").val();
    const season = $("#rss_season").val();
    const fuzzy_match = $("#fuzzy_match").prop("checked");
    let doubanid;
    let tmdbid = $("#rss_tmdbid").val();
    const over_edition = $("#over_edition").prop("checked");
    const filter_restype = $("#rss_restype").val();
    const filter_pix = $("#rss_pix").val();
    const filter_team = $("#rss_team").val();
    const filter_rule = $("#rss_rule").val();
    const save_path = $("#rss_save_path").val();
    const download_setting = $("#rss_download_setting").val();
    const total_ep = $("#rss_total_ep").val();
    const current_ep = $("#rss_current_ep").val();
    const rssid = $("#rss_id").val();
    if (!name) {
      $("#rss_name").addClass("is-invalid");
      return;
    } else {
      $("#rss_name").removeClass("is-invalid");
    }
    if (year && isNaN(year)) {
      $("#rss_year").addClass("is-invalid");
      return;
    } else {
      $("#rss_year").removeClass("is-invalid");
    }
    if (!fuzzy_match && !season && (mtype == "TV" || mtype == "电视剧")) {
      $("#rss_season").addClass("is-invalid");
      return;
    } else {
      $("#rss_season").removeClass("is-invalid");
    }
    if (total_ep && isNaN(total_ep)) {
      $("#rss_total_ep").addClass("is-invalid");
      return;
    } else {
      $("#rss_total_ep").removeClass("is-invalid");
    }
    if (current_ep && isNaN(current_ep)) {
      $("#rss_current_ep").addClass("is-invalid");
      return;
    } else {
      $("#rss_current_ep").removeClass("is-invalid");
    }
    if (tmdbid && tmdbid.startsWith("DB:")) {
      doubanid = tmdbid.replace("DB:", "");
      tmdbid = "";
    } else {
      doubanid = "";
    }
    //订阅站点
    let rss_sites = [];
    let rss_all = true;
    $("input[name=rss_sites]").each(function () {
      if ($(this).prop("checked")) {
        rss_sites.push($(this).val());
      } else {
        rss_all = false;
      }
    });
    if (rss_all) {
      rss_sites = [];
    }
    //搜索站点
    let search_sites = [];
    if (!fuzzy_match) {
      let search_all = true;
      $("input[name=search_sites]").each(function () {
        if ($(this).prop("checked")) {
          search_sites.push($(this).val());
        } else {
          search_all = false;
        }
      });
      if (search_all) {
        search_sites = [];
      }
    }
    const data = {
      "type": mtype,
      "name": name,
      "year": year,
      "season": season,
      "fuzzy_match": fuzzy_match,
      "doubanid": doubanid,
      "tmdbid": tmdbid,
      "rss_sites": rss_sites,
      "search_sites": search_sites,
      "over_edition": over_edition,
      "filter_restype": filter_restype,
      "filter_pix": filter_pix,
      "filter_team": filter_team,
      "filter_rule": filter_rule,
      "save_path": save_path,
      "download_setting": download_setting,
      "total_ep": total_ep,
      "current_ep": current_ep,
      "rssid": rssid,
    };
    $("#modal-manual-rss").modal("hide");
    show_wait_process();
    ajax_post("add_rss_media", data, function (ret) {
      hide_wait_process();
      if (ret.code === 0) {
        if (CURRENT_PAGE_URI.startsWith("tv_rss")) {
          navmenu("tv_rss");
        } else if (CURRENT_PAGE_URI.startsWith("movie_rss")) {
          navmenu("movie_rss");
        } else {
          show_rss_success_modal(ret.rssid, type, name + " 添加订阅成功！")
        }
      } else {
        if (CURRENT_PAGE_URI.startsWith("tv_rss") || CURRENT_PAGE_URI.startsWith("movie_rss")) {
          show_fail_modal(`${ret.name} 订阅失败：${ret.msg}！`, function () {
            $("#modal-manual-rss").modal("show");
          });
        } else {
          show_fail_modal(`${ret.name} 订阅失败：${ret.msg}！`);
        }
      }
    });
  }

  //初始化下拉框
  $("#rss_season").empty().append('<option value="">请选择</option>');
  for (let i = 1; i <= 50; i++) {
    $("#rss_season").append('<option value="' + i + '">第' + i + '季</option>');
  }

  //RSS站点批量选择
  let rss_sites_select_all = true;

  function rss_sites_select() {
    if (rss_sites_select_all) {
      // 取消全选
      $(".rss_sites_container").find("input[type=checkbox]").each(function () {
        $(this).prop("checked", false);
      });
      rss_sites_select_all = false;
      $("#rss_sites_select_btn").text("全选");
    } else {
      //全选
      $(".rss_sites_container").find("input[type=checkbox]").each(function () {
        $(this).prop("checked", true);
      });
      rss_sites_select_all = true;
      $("#rss_sites_select_btn").text("取消全选");
    }
  }

  // 选择模糊匹配
  function change_match_check(obj) {
    if ($(obj).prop("checked")) {
      $("#rss_search_sites_div").hide();
      $("#over_edition").prop("checked", false);
    } else {
      $("#rss_search_sites_div").show();
    }
  }

  // 选择洗版
  function change_over_edition_check(obj) {
    if ($(obj).prop("checked")) {
      $("#fuzzy_match").prop("checked", false);
      $("#rss_search_sites_div").show();
    }
  }


  //取消订阅
  function remove_rss_manual(type, name, year, rssid) {
    $("#modal-manual-rss").modal('hide');
    let page;
    if (CURRENT_PAGE_URI.startsWith("tv_rss")) {
      page = "tv_rss";
    } else if (CURRENT_PAGE_URI.startsWith("movie_rss")) {
      page = "movie_rss";
    } else {
      page = undefined
    }
    remove_rss_media(name, year, type, rssid, page);
  }

  // 显示新增电视剧订阅
  function show_add_tvrss_media_modal() {
    // 刷新下拉框
    refresh_rss_download_setting_dirs();

    // 界面初始化
    $("#rss_id").val("");
    $("#rss_modal_title").text("新增订阅");
    $("#rss_type").val("TV");
    $("#rss_name").val("").attr("readonly", false);
    $("#rss_year").val("").attr("readonly", false);
    $("#rss_tmdbid").val("");
    $("#rss_season").val("");
    $("#rss_total_ep").val("");
    $("#rss_current_ep").val("");
    $("#fuzzy_match").prop("checked", false);
    $("#over_edition").prop("checked", false);
    $("#rss_restype").val('');
    $("#rss_pix").val('');
    $("#rss_team").val('');
    $("#rss_rule").val('');
    $("#rss_save_path").val('');
    $("#rss_download_setting").val('-1');
    $("#rss_sites_div").show().find("input[type=checkbox]").each(function () {
      $(this).prop("checked", false);
    });
    $("#rss_search_sites_div").show().find("input[type=checkbox]").each(function () {
      $(this).prop("checked", false);
    });
    $("#rss_delete_btn").hide();
    $("#modal-manual-rss").modal('show');
  }

  // 显示新增电影订阅
  function show_add_movierss_media_modal() {
    // 刷新下拉框
    refresh_rss_download_setting_dirs();

    // 界面初始化
    $("#rss_id").val("");
    $("#rss_modal_title").text("新增订阅");
    $("#rss_type").val("MOV");
    $("#rss_name").val("").attr("readonly", false);
    $("#rss_year").val("").attr("readonly", false);
    $("#rss_tmdbid").val("");
    $("#rss_tv_season_div").hide();
    $("#fuzzy_match").prop("checked", false);
    $("#over_edition").prop("checked", false);
    $("#rss_restype").val('');
    $("#rss_pix").val('');
    $("#rss_team").val('');
    $("#rss_rule").val('');
    $("#rss_save_path").val('');
    $("#rss_download_setting").val('-1');
    $("#rss_sites_div").show().find("input[type=checkbox]").each(function () {
      $(this).prop("checked", false);
    });
    $("#rss_search_sites_div").show().find("input[type=checkbox]").each(function () {
      $(this).prop("checked", false);
    });
    $("#rss_delete_btn").hide();
    $("#modal-manual-rss").modal('show');
  }

  // 显示编辑订阅
  function show_edit_rss_media_modal(rssid, type) {
    $("#system-media-modal").modal('hide');
    $("#rss_id").val(rssid);
    $("#rss_type").val(type);
    $("#rss_modal_title").text("编辑订阅");

    // 刷新下拉框
    refresh_rss_download_setting_dirs();

    // 获取订阅信息
    show_wait_process();
    ajax_post("rss_detail", {"rssid": rssid, "rsstype": type}, function (ret) {
      hide_wait_process();
      if (ret.code === 0) {
        $("#rss_tmdbid").val(ret.detail.tmdbid);
        $("#rss_name").val(ret.detail.name).attr("readonly", true);
        $("#rss_year").val(ret.detail.year).attr("readonly", true);
        if (type == "MOV" || type == "电影") {
          $("#rss_tv_season_div").hide();
          $("#rss_season").val("");
          $("#rss_total_ep").val("");
          $("#rss_current_ep").val("");
        } else {
          $("#rss_tv_season_div").show();
          if (ret.detail.season) {
            $("#rss_season").val(parseInt(ret.detail.season.replace("S", "")));
          } else {
            $("#rss_season").val("");
          }
          if (ret.detail.total_ep) {
            $("#rss_total_ep").val(ret.detail.total_ep);
          } else {
            $("#rss_total_ep").val("");
          }
          if (ret.detail.current_ep) {
            $("#rss_current_ep").val(ret.detail.current_ep);
          } else {
            $("#rss_current_ep").val("");
          }
        }
        if (!ret.detail.fuzzy_match) {
          $("#fuzz_match").prop("checked", false);
          $("#rss_search_sites_div").show();
        } else {
          $("#fuzzy_match").prop("checked", true);
          $("#rss_search_sites_div").hide();
        }
        if (ret.detail.over_edition) {
          $("#over_edition").prop("checked", true);
        } else {
          $("#over_edition").prop("checked", false);
        }
        $("#rss_restype").val(ret.detail.filter_restype);
        $("#rss_pix").val(ret.detail.filter_pix);
        $("#rss_team").val(ret.detail.filter_team);
        $("#rss_rule").val(ret.detail.filter_rule);
        $("#rss_save_path").val(ret.detail.save_path);
        $("#rss_download_setting").val(ret.detail.download_setting);
        $("#rss_sites_div").find("input[type=checkbox]").each(function () {
          if (ret.detail.rss_sites && (ret.detail.rss_sites.length === 0 || ret.detail.rss_sites.includes($(this).val()))) {
            $(this).prop("checked", true);
          } else {
            $(this).prop("checked", false);
          }
        });
        $("#rss_search_sites_div").find("input[type=checkbox]").each(function () {
          if (ret.detail.search_sites && (ret.detail.search_sites.length === 0 || ret.detail.search_sites.includes($(this).val()))) {
            $(this).prop("checked", true);
          } else {
            $(this).prop("checked", false);
          }
        });
        $("#rss_delete_btn").attr("href",
            `javascript:remove_rss_manual('${ret.detail.type}','${ret.detail.name}','${ret.detail.year}','${rssid}')`)
            .show();
        $("#modal-manual-rss").modal('show');
      }
    });
  }

  // 显示订阅成功（带后续操作）
  function show_rss_success_modal(rssid, type, text) {
    $("#system_success_action_message").text(text);
    if (rssid) {
      $("#system_success_action_btn").text("编辑订阅")
          .unbind('click').click(function () {
        $("#system-success-action-modal").modal('hide');
        show_edit_rss_media_modal(rssid, type);
      });
      ;
      $("#system_success_action_div").show();
    } else {
      $("#system_success_action_div").hide();
    }
    $("#system-success-action-modal").modal('show');
  }

  // 刷新规则下拉框
  function refresh_filter_select(obj_id, aync = true) {
    ajax_post("get_filterrules", {}, function (ret) {
      if (ret.code === 0) {
        let rule_select = $("#" + obj_id);
        rule_select.empty();
        rule_select.append(`<option value="">站点规则</option>`);
        for (let i = 0; i < ret.ruleGroups.length; i++) {
          rule_select.append(`<option value="${ret.ruleGroups[i].id}">${ret.ruleGroups[i].name}</option>`);
        }
      }
    }, aync);
  }

  // 刷新订阅站点列表
  var RSS_SITES_LENGTH = 0;

  function refresh_rsssites_select(obj_id, aync = true) {
    ajax_post("get_sites", {rss: true, basic: true}, function (ret) {
      if (ret.code === 0) {
        let rsssites_select = $("#" + obj_id);
        rsssites_select.empty();
        RSS_SITES_LENGTH = ret.sites.length;
        if (ret.sites.length > 0) {
          rsssites_select.parent().parent().show();
        } else {
          rsssites_select.parent().parent().hide();
        }
        for (let i = 0; i < ret.sites.length; i++) {
          rsssites_select.append(`
          <label class="form-selectgroup-item">
            <input type="checkbox" name="rss_sites" value="${ret.sites[i].name}" class="form-selectgroup-input">
            <span class="form-selectgroup-label">${ret.sites[i].name}</span>
          </label>
          `);
        }
      }
    }, aync);
  }

  // 刷新搜索站点列表
  function refresh_searchsites_select(obj_id, aync = true) {
    ajax_post("get_indexers", {check: true, basic: true}, function (ret) {
      if (ret.code === 0) {
        let searchsites_select = $("#" + obj_id);
        if (ret.indexers.length > 0) {
          searchsites_select.parent().parent().show();
        } else {
          searchsites_select.parent().parent().hide();
        }
        searchsites_select.empty();
        for (let i = 0; i < ret.indexers.length; i++) {
          searchsites_select.append(`
          <label class="form-selectgroup-item">
            <input type="checkbox" name="search_sites" value="${ret.indexers[i].name}" class="form-selectgroup-input">
            <span class="form-selectgroup-label">${ret.indexers[i].name}</span>
          </label>
          `);
        }
      }
    }, aync);
  }

  // 刷新保存路径
  function refresh_savepath_select(obj_id, aync = true, sid = "") {
    ajax_post("get_download_dirs", {sid: sid}, function (ret) {
      if (ret.code === 0) {
        let savepath_select = $("#" + obj_id);
        savepath_select.empty();
        savepath_select.append(`<option value="">自动</option>`);
        for (let i = 0; i < ret.paths.length; i++) {
          savepath_select.append(`<option value="${ret.paths[i]}">${ret.paths[i]}</option>`);
        }
      }
    }, aync);
  }

  // 刷新下载设置
  function refresh_downloadsetting_select(obj_id, aync = true) {
    ajax_post("get_download_setting", {}, function (ret) {
      if (ret.code === 0) {
        let downloadsetting_select = $("#" + obj_id);
        downloadsetting_select.empty();
        for (let i = 0; i < ret.data.length; i++) {
          downloadsetting_select.append(`<option value="${ret.data[i].id}">${ret.data[i].name}</option>`);
        }
      }
    }, aync);
  }

  // 刷新订阅框的下载设置及目录等选项
  function refresh_rss_download_setting_dirs(){
    show_wait_process();
    refresh_rsssites_select("rss_sites_group", false);
    refresh_searchsites_select("rss_search_sites_group");
    refresh_filter_select("rss_rule");
    refresh_downloadsetting_select("rss_download_setting", false);
    refresh_savepath_select("rss_save_path", true, $("#rss_download_setting").val());
    hide_wait_process();
  }

  // 刷新下载框的下载设置及目录选项
  function refresh_search_download_setting_dirs(){
    refresh_downloadsetting_select("search_download_setting", false);
    refresh_savepath_select("search_download_dir", true, $("#search_download_setting").val());
  }

  // 显示下载提示框
  function show_download_modal(id, name, func) {
    $("#search_download_id").val(id);
    $("#search_download_name").val(name);
    $("#search_download_message").text("下载 " + name);
    // 根据下载设置刷新下载目录选项
    refresh_search_download_setting_dirs();
    // 绑定下载按钮事件
    if (func) {
      $("#search_download_btn").unbind("click").click(func);
    }else{
      $("#search_download_btn").unbind("click").click(download_link);
    }
    $("#modal-search-download").modal('show');
  }

  //点击链接下载
  function download_link() {
    const id = $("#search_download_id").val();
    const name = $("#search_download_name").val();
    const dir = $("#search_download_dir").val();
    const setting = $("#search_download_setting").val();
    $("#modal-search-download").modal('hide');
    ajax_post("download", {"id": id, "dir": dir, "setting": setting}, function (ret) {
      if (ret.retcode === 0) {
        show_success_modal(`${name} 添加下载成功！`);
      } else {
        show_fail_modal(`${name} 添加下载失败 ${ret.retmsg}！`);
      }
    });
  }

</script>

<!-- 页面组件 -->
<script type="text/javascript">

  //刷新tooltip
  function fresh_tooltip() {
    const tooltipTriggerList = Array.prototype.slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
    tooltipTriggerList.map(function (tooltipTriggerEl) {
      return new bootstrap.Tooltip(tooltipTriggerEl)
    });
  }

  //打开路径选择框
  function openFileBrowser(el, root, filter, on_folders, on_files, close_on_select) {
    if (on_folders === undefined) on_folders = true;
    if (on_files === undefined) on_files = true;
    if (!filter && !on_files) filter = 'HIDE_FILES_FILTER';
    if (!root.trim()) root = "/";
    let p = $(el);
    // Skip is fileTree is already open
    if (p.next().hasClass('fileTree')) return null;
    // create a random id
    const r = Math.floor((Math.random() * 1000) + 1);
    // Add a new span and load fileTree
    p.after("<div id='fileTree" + r + "' class='fileTree card shadow' style='z-index: 99999'></div>");
    const ft = $('#fileTree' + r);
    ft.fileTree({
          script: 'dirlist',
          root: root,
          filter: filter,
          allowBrowsing: true
        },
        function (file) {
          if (on_files) {
            p.val(file);
            p.trigger('change');
            if (close_on_select) {
              ft.slideUp('fast', function () {
                ft.remove();
              });
            }
          }
        },
        function (folder) {
          if (on_folders) {
            p.val(folder);
            p.trigger('change');
            if (close_on_select) {
              $(ft).slideUp('fast', function () {
                $(ft).remove();
              });
            }
          }
        });
    // Format fileTree according to parent position, height and width
    ft.css({'left': p.position().left, 'top': (p.position().top + p.outerHeight()), 'width': (p.parent().width())});
    // close if click elsewhere
    $(document).mouseup(function (e) {
      if (!ft.is(e.target) && ft.has(e.target).length === 0) {
        ft.slideUp('fast', function () {
          $(ft).remove();
        });
      }
    });
    // close if parent changed
    p.bind("keydown", function () {
      ft.slideUp('fast', function () {
        $(ft).remove();
      });
    });
    // Open fileTree
    ft.slideDown('fast');
  }

  //初始化目录选择控件
  function init_filetree_element() {
    $('.filetree-folders-only').each(function () {
      $(this).attr("onclick", "openFileBrowser(this,$(this).val(),'',true,false);");
    });
    $('.filetree-files-only').each(function () {
      $(this).attr("onclick", "openFileBrowser(this,$(this).val(),'',false,true);");
    });
  }

  //鼠标提示等待
  function make_cursor_busy() {
    const body = document.querySelector("body");
    body.style.cursor = "wait";
  }

  //鼠标取消等待
  function cancel_cursor_busy() {
    const body = document.querySelector("body");
    body.style.cursor = "default";
  }

  // 名称识别测试
  function media_name_test(name, result_div, func) {
    if (!name) {
      return;
    }
    ajax_post("name_test", {"name": name}, function (ret) {
      if (func) {
        func();
      }
      if (ret.code === 0) {
        media_name_test_ui(ret.data, result_div);
      }
    });
  }

  // 处理识别结果UI
  function media_name_test_ui(data, result_div) {
    let content = '';
    let ignored_words = [];
    let replaced_words = [];
    let offset_words = [];
    if (data.ignored_words) {
      ignored_words = data.ignored_words;
    }
    if (data.replaced_words) {
      replaced_words = data.replaced_words;
    }
    if (data.offset_words) {
      offset_words = data.offset_words;
    }
    const words = ignored_words + replaced_words + offset_words;
    if (words.length !== 0) {
      if (data.org_string) {
        content = `${content}<div class="mb-3" ><label class="form-label">识别使用名称：<span class="badge badge-outline text-wrap text-cyan me-1 mb-1" style="vertical-align: middle;white-space: normal;text-align: left;word-break: break-all;" title="自定义识别词过滤后识别用名">${data.org_string}</span></label></div>`;
      }
      if (ignored_words.length !== 0) {
        let ignored_word_content = '';
        for (ignored_word of ignored_words) {
          ignored_word_content = `${ignored_word_content}<span class="badge badge-outline text-wrap text-cyan me-1 mb-1" style="vertical-align: middle;">${ignored_word}</span>`;
        }
        content = `${content}<div class="mb-3"><label class="form-label">应用屏蔽词：${ignored_word_content}</label></div>`;
      }
      if (replaced_words.length !== 0) {
        let replaced_words_content = '';
        for (replaced_word of replaced_words) {
          replaced_words_content = replaced_words_content + `<span class="badge badge-outline text-wrap text-cyan me-1 mb-1" style="vertical-align: middle;">${replaced_word}</span>`;
        }
        content = `${content}<div class="mb-3"><label class="form-label">应用替换词：${replaced_words_content}</label></div>`;
      }
      if (offset_words.length !== 0) {
        let offset_words_content = '';
        for (offset_word of offset_words) {
          offset_words_content = offset_words_content + `<span class="badge badge-outline text-wrap text-cyan me-1 mb-1" style="vertical-align: middle;">${offset_word}</span>`;
        }
        content = `${content}<div class="mb-3"><label class="form-label">应用集数偏移：${offset_words_content}</label></div>`;
      }
    }
    if (data.type) {
      content = `${content}<span class="badge bg-blue me-1 mb-1" title="类型">${data.type}</span>`;
    }
    if (data.category) {
      content = `${content}<span class="badge bg-blue me-1 mb-1" title="类别">${data.category}</span>`;
    }
    if (data.name) {
      const name_query_link = `https://www.themoviedb.org/search?query=${encodeURI(data.name)}`;
      content = `${content}<span title="识别名称"><a class="badge bg-yellow me-1 mb-1" href="${name_query_link}" target="_blank">${data.name}</a></span>`;
    }
    if (data.title) {
      content = `${content}<span class="badge bg-green me-1 mb-1" title="标题">${data.title}</span>`;
    } else {
      content = `${content}<span class="badge bg-red me-1 mb-1" title="标题">未匹配TMDB</span>`;
    }
    if (data.tmdbid) {
      content = `${content}<span title="TMDB ID"><a class="badge bg-green me-1 mb-1" href="${data.tmdblink}" target="_blank">${data.tmdbid}</a></span>`;
    }
    if (data.year) {
      content = `${content}<span class="badge bg-orange me-1 mb-1" title="年份">${data.year}</span>`;
    }
    if (data.season_episode) {
      content = `${content}<span title="季集"><a class="badge bg-orange me-1 mb-1" href="${data.tmdb_S_E_link}" target="_blank">${data.season_episode}</a></span>`;
    }
    if (data.part) {
      content = `${content}<span class="badge bg-orange me-1 mb-1" title="分集">${data.part}</span>`;
    }
    if (data.restype) {
      content = `${content}<span class="badge me-1 mb-1" title="质量">${data.restype}</span>`;
    }
    if (data.effect) {
      content = `${content}<span class="badge me-1 mb-1" title="特性">${data.effect}</span>`;
    }
    if (data.pix) {
      content = `${content}<span class="badge me-1 mb-1" title="分辨率">${data.pix}</span>`;
    }
    if (data.video_codec) {
      content = `${content}<span class="badge me-1 mb-1" title="视频编码">${data.video_codec}</span>`;
    }
    if (data.audio_codec) {
      content = `${content}<span class="badge me-1 mb-1" title="音频编码">${data.audio_codec}</span>`;
    }
    if (data.team) {
      content = `${content}<span class="badge bg-cyan me-1 mb-1" title="制作组/字幕组">${data.team}</span>`;
    }
    $(`#${result_div}`).empty().append(content);
  }

  // 显示手动识别转移框
  // manual_type: 1-未识别手动识别，2-历史记录手动识别，3-自定义识别
  // media_type: 电影，电视剧，动漫
  function show_manual_transfer_modal(manual_type, inpath, syncmod, media_type, unknown_id, transferlog_id) {
    // 初始化类型
    if (!syncmod) {
      syncmod = '{{ SyncMod }}';
    }
    $("#rename_manual_type").val(manual_type);
    if (manual_type === 3) {
      $('#rename_header').text("自定义识别");
      $('#rename_path_div').hide();
      $('#rename_inpath_div').show();
      $('#rename_outpath_div').show();
      $("#rename_inpath").val(inpath);
      $("#rename_outpath").val('');
      $("#rename_syncmod_customize").val(syncmod);
      $("#unknown_id").val("");
      $("#transferlog_id").val("");
    } else {
      $('#rename_header').text("手动识别");
      $('#rename_path_div').show();
      $('#rename_inpath_div').hide();
      $('#rename_outpath_div').hide();
      $("#rename_path").val(inpath);
      $("#rename_syncmod_manual").val(syncmod);
      $("#unknown_id").val(unknown_id);
      $("#transferlog_id").val(transferlog_id);
    }
    // 初始化季列表
    $("#rename_season").empty()
        .append('<option value="" selected>请选择</option>');
    for (let i = 0; i <= 50; i++) {
      $("#rename_season").append('<option value="' + i + '">第' + i + '季</option>');
    }
    // 初始化媒体类型
    if (media_type === "电视剧") {
      $("#rename_type_tv").prop("checked", true);
      $("#rename_type_mov").removeProp("checked");
      $("#rename_type_anime").removeProp("checked");
      $("#rename_season_div").show();
      $("#rename_episode_div").show();
    } else if (media_type === "动漫") {
      $("#rename_type_anime").prop("checked", true);
      $("#rename_type_tv").removeProp("checked");
      $("#rename_type_mov").removeProp("checked");
      $("#rename_season_div").show();
      $("#rename_episode_div").show();
    } else {
      $("#rename_type_mov").prop("checked", true);
      $("#rename_type_tv").removeProp("checked");
      $("#rename_type_anime").removeProp("checked");
      $("#rename_season_div").hide();
      $("#rename_episode_div").hide();
      $("#rename_season").val("");
    }

    // 清空输入框
    $("#rename_min_filesize").val("");
    $("#rename_episode").val("");
    $("#rename_episode_details").val("");
    $("#rename_episode_offset").val("");
    $("#rename_season").val("");
    $("#rename_tmdb").val("");

    // 显示窗口
    $("#modal-media-identification").modal("show");

  }

  // 执行手动识别转移
  function manual_media_transfer() {
    let syncmod;
    const manual_type = $("#rename_manual_type").val();
    const type = $('input:radio[name=rename_type]:checked').val();
    const path = $("#rename_path").val();
    const inpath = $("#rename_inpath").val();
    const outpath = $("#rename_outpath").val();
    if (manual_type == '3') {
      syncmod = $("#rename_syncmod_customize").val();
    } else {
      syncmod = $("#rename_syncmod_manual").val();
    }
    const tmdb = $("#rename_tmdb").val();
    const season = $("#rename_season").val();
    const episode_format = $("#rename_episode").val();
    const episode_details = $("#rename_episode_details").val();
    const episode_offset = $("#rename_episode_offset").val();
    const min_filesize = $("#rename_min_filesize").val();
    const logid = $("#transferlog_id").val();
    const unknown_id = $('#unknown_id').val();

    if (manual_type == '1' && !unknown_id) {
      return;
    }

    if (manual_type == '2' && !logid) {
      return;
    }

    if (manual_type == '3') {
      if (!inpath) {
        $("#rename_inpath").addClass("is-invalid");
        return;
      } else {
        $("#rename_inpath").removeClass("is-invalid");
      }
    } else {
      if (!path) {
        $("#rename_path").addClass("is-invalid");
        return;
      } else {
        $("#rename_path").removeClass("is-invalid");
      }
    }

    if (min_filesize && isNaN(min_filesize)) {
      $("#rename_min_filesize").addClass("is-invalid");
      return;
    } else {
      $("#rename_min_filesize").removeClass("is-invalid");
    }

    if (episode_details && !/^\d{1,5}([,-]\d{1,5})?$/.test(episode_details)) {
      $("#rename_episode_details").addClass("is-invalid");
      return;
    } else {
      $("#rename_episode_details").removeClass("is-invalid");
    }
    if (episode_offset && !/^-?\d{1,5}$/.test(episode_offset)) {
      $("#rename_episode_offset").addClass("is-invalid");
      return;
    } else {
      $("#rename_episode_offset").removeClass("is-invalid");
    }

    // 开始处理
    const data = {
      "inpath": inpath,
      "outpath": outpath,
      "syncmod": syncmod,
      "type": type,
      "tmdb": tmdb,
      "season": season,
      "episode_format": episode_format,
      "episode_details": episode_details,
      "episode_offset": episode_offset,
      "min_filesize": min_filesize,
      "unknown_id": unknown_id,
      "path": path,
      "logid": logid
    };
    $("#identification_action_btn").attr("disabled", true)
        .text("处理中...");
    $("#rename_udf_retmsg").hide()
    $("#rename_retmsg").hide()
    if (manual_type == '3') {
      cmd = "rename_udf"
    } else {
      cmd = "rename"
    }
    ajax_post(cmd, data, function (ret) {
      $("#identification_action_btn").attr("disabled", false)
          .text("转移");
      if (ret.retcode == 0) {
        $('#modal-media-identification').modal('hide');
        show_success_modal("处理成功！", function () {
          if (manual_type == '2') {
            navmenu('history');
          } else {
            navmenu('unidentification');
          }
        });
      } else {
        //处理失败
        regmsg = ret.retmsg;
        if (manual_type == '3') {
          $("#rename_udf_retmsg").show()
              .text(regmsg)
        } else {
          $("#rename_retmsg").show()
              .text(regmsg)
        }
      }
    });

  }

</script>

<!-- 首页功能 -->
<script type="text/javascript">
  //当前页面地址
  let CURRENT_PAGE_URI = "";

  //导航点击
  function navmenu(page) {
    $("#navbar-menu li").find("a").removeClass("active").each(function () {
      if ($(this).attr("onclick") && $(this).attr("onclick").includes("navmenu('" + page + "')")) {
        $(this).addClass("active");
        if ($(this).hasClass('dropdown-item')) {
          $(this).parent().addClass("show");
        }
      }
    });
    $("#navbar-menu").collapse('hide');
    show_wait_process();
    $(".page-wrapper").unbind('scroll');
    page = page.replaceAll(" ", "%20");
    $("#page_content").load(page, {}, function (response, status, xhr) {
      hide_wait_process();
      if ($("#page_content").find("title").first().text() == "登录 - NAStool") {
        window.location.reload();
      } else {
        fresh_tooltip();
        init_filetree_element();
      }
      if (page != CURRENT_PAGE_URI) {
        ScrollToTop();
        CURRENT_PAGE_URI = page;
      }
    });
  }

  //刷新LOG标志
  let refresh_logging_flag = false;

  //开始刷新日志
  function start_logging() {
    refresh_logging_flag = true;
    refresh_logging();
  }

  //停止刷新日志
  function stop_logging() {
    refresh_logging_flag = false;
  }

  //刷新日志
  function refresh_logging(flag) {
    let refresh_new = $("#logging_content").children().length;
    ajax_post("logging", {"refresh_new": refresh_new}, function (ret) {
      if (ret.loglist) {
        let log_list = ret.loglist;
        let tdstyle = "padding-top: 0.5rem; padding-bottom: 0.5rem";
        let tbody = "";
        for (let i = 0; i < log_list.length; i++) {
          const log =  log_list[i];
          let text = log.text;
          const source = log.source;
          const time = log.time;
          const level = log.level;
          let tcolor = '';
          let bgcolor = '';
          let tstyle = '';
          if (level === "WARN") {
            tcolor = "text-warning";
            bgcolor = "bg-warning";
          } else if (level === "ERROR") {
            tcolor = "text-danger";
            bgcolor = "bg-danger";
          } else if (source === "System") {
            tcolor = "text-info";
            bgcolor = "bg-info";
          } else {
            tcolor = "text";
          }
          if (["Rmt", "Subtitle"].includes(source) && text.includes(" 到 ")) {
            tstyle = `white-space: pre;`
            text = text.replace(/\s到\s/, "\n=> ")
          }
          if (text.includes("http") || text.includes("magnet")) {
            tstyle = `word-break: break-all;`
            text = text.replace(/：((?:http|magnet).+?)(?:\s|$)/g, "：<a href='$1' target='_blank'>$1</a>")
          }
          tbody = `${tbody}
                    <tr>
                    <td style="${tdstyle}"><span class="${tcolor}">${time}</span></td>
                    <td style="${tdstyle}"><span class="badge ${bgcolor}">${source}</span></td>
                    <td style="${tdstyle}"><span class="${tcolor}" style="${tstyle}">${text}</span></td>
                    </tr>`;
        }
        let bool_ToScrolTop = ($("#logging_table").scrollTop() + $("#logging_table").prop("offsetHeight")) >= $("#logging_table").prop("scrollHeight");
        $("#logging_content").append(tbody);
        if (bool_ToScrolTop){
          setTimeout(function () {
            $("#logging_table").scrollTop($("#logging_table").prop("scrollHeight"));
          }, 500);
        }
      }
      if ($("#modal-logging").is(":hidden") && flag) {
        stop_logging();
      }
      if (refresh_logging_flag == true) {
        setTimeout("refresh_logging(true)", 2000);
      }
    });
  }

  //暂停实时日志
  function pause_logging() {
    if (refresh_logging_flag == true) {
      stop_logging();
      $("#logging_stop_btn").text("开始")
    } else {
      start_logging();
      $("#logging_stop_btn").text("暂停")
    }
  }

  //实时日志关闭
  $("#logging_close_btn").click(function () {
    stop_logging();
  });

  $("#logging_close_head").click(function () {
    stop_logging();
  });

  // 显示实时日志
  function show_logging_modal() {
    start_logging();
    $('#modal-logging').modal('show');
  }

  //刷新消息中心
  function refresh_message(time_str) {
    ajax_post("refresh_message", {"lst_time": time_str}, function (ret) {
      if (ret.code === 0) {
        let lst_time = ret.lst_time;
        const msgs = ret.message;
        for (let i = 0; i < msgs.length; i++) {
          $("#system-messages").prepend(msgs[i]);
        }
        setTimeout("refresh_message('" + lst_time + "')", 10000);
      }
    });
  }

  // 检查新版本
  const AppVersion = "{{ AppVersion }}".split(" ")[0];
  let NewVersion = '';
  $("#new_version_tip").hide();

  function check_new_version() {
    ajax_post("version", {}, function (ret) {
      if (ret.code === 0) {
        if (ret.version != AppVersion) {
          $("#new_version_info").html(ret.info);
          $("#new_version_tip").show();
          NewVersion = ret.version;
        }
      }
    });
  }

  //检查系统是否在线
  function check_system_online() {
    ajax_post("refresh_process", {type: "restart"}, function (ret) {
        if (ret.code === -1) {
          logout();
        } else {
          setTimeout("check_system_online()", 1000);
        }
      });
  }

  //注销
  function logout() {
    ajax_post("logout", {}, function (ret) {
      window.location.href = "/";
    });
  }

  //重启
  function restart() {
    show_confirm_modal("立即重启系统？", function () {
      hide_confirm_modal();
      ajax_post("restart", {}, function (ret) {
      });
      show_wait_process(true);
      setTimeout("check_system_online()", 5000);
    });
  }

  //更新
  function update(version) {
    let title;
    if (version) {
      title = "是否确认更新到 " + version + " 版本？";
    } else {
      title = "将从Github拉取最新程序代码并重启，是否确认？";
    }
    show_confirm_modal(title, function () {
      hide_confirm_modal();
      ajax_post("update_system", {}, function (ret) {
      });
      show_wait_process(true);
      setTimeout("check_system_online()", 5000);
    });
  }

  //滚动到顶步
  function ScrollToTop() {
    $("#page_wrapper").animate({
      scrollTop: 0
    }, 500);
  }
</script>

<!-- 事件  -->
<script type="text/javascript">
  //浏览器兼容
  String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2)
  }

  //事件
  $(document).ready(function () {
    // 搜索输入框
    $('.home_search_word').bind('keypress', function (event) {
      if (event.keyCode == "13") {
        if (!$(this).val()) {
          return;
        }
        navmenu('medialist?s=' + $(this).val() + '&f=1');
        $(this).val('');
      }
    });

    // tooltip点击事件处理，阻止冒泡到上级元素，避免比如`点击tooltip切换了switch`的问题
    $('body').on('click', 'span[data-bs-toggle="tooltip"]', function (e) {
      e.preventDefault();
      e.stopPropagation();
    });

    /**
     * 计算菜单列表高度
     * @return {number}
     */
    function computeMenuListHeight() {
      // '#navbar-menu > .order-first' 要打开菜单后才会显示，所以这里取固定值36
      const menuFirstHeight = 36;
      // 这个是经过测试得到的数值
      const extra = 120;
      return $('.navbar-brand').outerHeight() + menuFirstHeight + extra
    }

    /**
     * 更新菜单列表高度
     */
    function updateMenuListHeight() {
      const height = computeMenuListHeight();
      $('.navbar ul.navbar-nav').css({
        maxHeight: 'calc(100vh - ' + height + 'px)'
      })
    }

    updateMenuListHeight()

    //单选框事件
    $('input[type=radio][name=rename_type]').change(function () {
      if (this.value == 'MOV') {
        $("#rename_season_div").hide();
        $("#rename_episode_div").hide();
        $("#rename_season").val('');
      } else {
        $("#rename_season_div").show();
        $("#rename_episode_div").show();
      }
    });

    //加载页面
    const go_page = "{{ GoPage }}";
    if (go_page) {
      navmenu(go_page);
    } else {
      //打开第一个页面
      $("#navbar-menu").find("a[onclick]").first().trigger('click');
    }

    {% if "系统设置" in UserPris %}
      //检查版本升级
      check_new_version();
      //刷新消息
      refresh_message("");
    {% endif %}

    {% if not TMDBFlag %}
      //检查tmdb配置
      show_fail_modal("请先配置TMDB API Key，并修改登录密码！", function () {
        navmenu('basic');
      });
    {% endif %}

  });
</script>
</body>

</html>